﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Table.Properties
{
    [XmlRoot("tblCellMar", Namespace = Constants.WordMain)]
    class CellMargin : XmlSerializable, ITablePropElement
    {
        [XmlElement("top", Namespace = Constants.WordMain)]
        public MarginDefinition Top { get; set; }

        [XmlElement("left", Namespace = Constants.WordMain)]
        public MarginDefinition Left { get; set; }

        [XmlElement("bottom", Namespace = Constants.WordMain)]
        public MarginDefinition Bottom { get; set; }

        [XmlElement("right", Namespace = Constants.WordMain)]
        public MarginDefinition Right { get; set; }

        public CellMargin() { }

        public void Copy(object obj)
        {
            if (obj is CellMargin)
            {
                this.Top = (obj as CellMargin).Top;
                this.Left = (obj as CellMargin).Left;
                this.Right = (obj as CellMargin).Right;
                this.Bottom = (obj as CellMargin).Bottom;
            }
        }
    }

    #region MarginDefinition

    public class MarginDefinition : XmlSerializable
    {
        [Optional]
        [XmlAttribute("w", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> Width { get; set; }

        [Optional]
        [XmlAttribute("type", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_TblWidth> Type { get; set; }

        public MarginDefinition() { }
    }

    #endregion
}
